package edu.serg.mbar.algorithms.functions;

import java.util.Vector;

import org.apache.log4j.Logger;

import edu.serg.mbar.ucon.interfaces.IFunction;

public class LogicalAnd implements IFunction {
	Logger log =Logger.getLogger(TimeLessThan.class);
	/**
	 * Function for the implementation of Function for LogicalAND operation
	 * 
	 * @param
	 * The Vector of Objects representing boolean values on which the logical and function will be applied
	 * 
	 * @return
	 * returns an object representing the boolean value, the boolean value is true if all values in the Vector of objects passed on to the function as an argument to the function are true and returns a false value if any of the value in the vector of objects is false 
	 */
	@Override
	public Object evaluate(Vector<Object> param) {
		// TODO Auto-generated method stub
		boolean result =true  ;
		log.debug("applying the logical and Function to " + param.size() +" items");
//		log.debug("The total number of Elements in the Vector is " + param.size());
		for (int i=0; i<param.size();i++)
		{
			result = (Boolean) param.elementAt(i);
			log.debug("applying logicalAND function the element at " + i +" whose value is " + result);
			// if the result is false then increase the value of i to exit loop
			if (result==false ) 
			{
			i=param.size() + 1;	
			}
		}
		return result;
	}

}
